package test.pcs;

import com.payment.lc.pcs.client.wrap.service.ProductionWrapService;
import com.payment.lc.pcs.common.enums.*;
import com.payment.lc.pcs.service.api.DynamicDataService;
import com.payment.lc.pcs.service.api.ProductionService;
import com.payment.lc.pcs.service.api.fund.JMFundService;
import com.payment.lc.pcs.service.bo.fund.ImportResponse;
import com.payment.lc.pcs.service.bo.fund.JMFundBasicInfo;
import com.payment.lc.pcs.service.bo.fund.JMFundExtInfo;
import com.payment.lc.pcs.service.bo.fund.JMFundFeeInfo;
import com.payment.lc.pcs.service.domain.*;
import com.payment.lc.pcs.service.request.GetFundListReq;
import com.payment.lc.pcs.service.response.GetFundListResp;
import com.payment.lc.pcs.service.util.ProductionItem;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import test.BaseTest;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * Created on 2016/8/8.
 */
public class Demo1PcsTest1 extends BaseTest {
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    @Autowired
    ProductionService productionService;

    @Autowired
    DynamicDataService dynamicDataService;

    @Autowired
    JMFundService jmFundService;

    @Autowired
    ProductionWrapService productionWrapService;


//    @Test
    public void test() {
        test10();
    }

    void test10() {
        ListWrapper<Production> productions = productionService.getDisplayUpOrderedProductions(GroupType.MobileFrontPageGroup, "DingqiList");
        print(productions);
        productions = productionService.getDisplayDownOrderedProductions(GroupType.MobileFrontPageGroup, "DingqiList");
        print(productions);
        productions = productionService.getProductionsStatusInsensitive(GroupType.MobileFrontPageGroup, "DingqiList");
        print(productions);
    }

    void test9() {
        ListWrapper<ProductionItem> xx = productionService.getDisplayUpOrderedCategoryAndProductions(GroupType.MobileFrontPageGroup);
        print(xx);
    }

    void test8() {
        GetFundListReq getFundListReq = new GetFundListReq();
        getFundListReq.setStart(0);
        getFundListReq.setLimit(20);
        getFundListReq.setNameOrCode("qd");
        GetFundListResp searchList = jmFundService.getSearchList(getFundListReq);
        System.out.println(searchList.getTotal());
        print(searchList);
    }

    void test7() {
        FundsProductionV2 fundsV2 = productionService.getFundsV2("JM118002");
        print(fundsV2);
    }


    void importBasic() {
        JMFundBasicInfo basicInfo = new JMFundBasicInfo();
        FundsProductionV2 fundsV2 = new FundsProductionV2();
        fundsV2.setDividendType(DividendType.ReInvest);
        fundsV2.setProfitChangeFlag(true);
        basicInfo.setFund(fundsV2);
        basicInfo.setFundCode("test_2");
        basicInfo.setName("华安德国龙头(DAX)ETF联接(QDII)");
        basicInfo.setProductionStatus(ProductionStatus.Both);
        basicInfo.setRiskClass(RiskClass.Low);

        ImportResponse resp = jmFundService.importBasicInfo(basicInfo);
        print(resp);

    }

    void test5() {
        ImportResponse fee = jmFundService.finshImport("fee", "20170111");
        print(fee);
    }

    void test1() {
        ListWrapper<Production> dingqiMore = productionService.getDisplayDownOrderedProductions(GroupType.MobileFrontPageGroup, "HuoqiList");
        print(dingqiMore);
        Production production = productionService.getProduction("JM373010");
        print(production);
        Object funds = productionService.getFunds("JM373010");
        print(funds);
    }

    void importFee() {
        String fundCode = "001735";
        List<ProductionFeeV2> fees = new ArrayList<ProductionFeeV2>();

        ProductionFeeV2 fee = new ProductionFeeV2();
        fee.setValueType(ValueType.FixedAmount);
        fee.setBizType(BizType.Fundin);
        fee.setFeeType(FeeType.MonthRate);
        fee.setDayLowerBound(0);
        fee.setDayUpperBound(1);
        fee.setFeeRate(new BigDecimal(3.0));
        fee.setBatchId("20170115");
        fee.setFundFeeType("discount_rate");
        fees.add(fee);

        JMFundFeeInfo feeInfo = new JMFundFeeInfo();
        feeInfo.setFees(fees);
        feeInfo.setFundCode(fundCode);

        ImportResponse importResponse = jmFundService.importFeeInfo(feeInfo);
        print(importResponse);

        fees = new ArrayList<ProductionFeeV2>();
        fee.setValueType(ValueType.FixedAmount);
        fee.setBizType(BizType.Fundin);
        fee.setFeeType(FeeType.MonthRate);
        fee.setDayLowerBound(0);
        fee.setDayUpperBound(1);
        fee.setFeeRate(new BigDecimal(5.0));
        fee.setBatchId("20170115");
        fee.setFundFeeType("standard_rate");
        fees.add(fee);
        feeInfo.setFees(fees);
        importResponse = jmFundService.importFeeInfo(feeInfo);
        print(importResponse);

        fees = new ArrayList<ProductionFeeV2>();
        fee = new ProductionFeeV2();
        fee.setValueType(ValueType.FixedAmount);
        fee.setBizType(BizType.Fundin);
        fee.setFeeType(FeeType.MonthRate);
        fee.setDayLowerBound(1);
        fee.setDayUpperBound(3);
        fee.setFeeRate(new BigDecimal(2.0));
        fee.setBatchId("20170115");
        fee.setFundFeeType("standard_rate");
        fees.add(fee);
        feeInfo.setFees(fees);
        importResponse = jmFundService.importFeeInfo(feeInfo);
        print(importResponse);

//        jmFundService.finshImport("fee", "20170112");
    }

    void importExtInfo() {

        String str = "{\n" +
                "\"innerCode\":102006860,\n" +
                "\"fundID\":102006858,\n" +
                "\"fundCode\":\"001735\",\n" +
                "\"fundName\":\" 广发百发大数据策略成长灵活配置混合型证券投资基金\",\n" +
                "\"fundShortName\":\" 广发百发大数据成长混合 E\",\n" +
                "\"estabDate\":\"2015-11-18 00:00:00\",\n" +
                "\"orgCode\":0,\n" +
                "\"orgFullName\":\"\",\n" +
                "\"managerCode\":200032347,\n" +
                "\"managerName\":\" 广发基金管理有限公司\",\n" +
                "\"trupCode\":200001191,\n" +
                "\"trupName\":\" 兴业银行股份有限公司\",\n" +
                "\"fundType\":2,\n" +
                "\"fundTypeMark\":\" 普通契约型开放式\",\n" +
                "\"fundStatus\":4,\n" +
                "\"fundStatusMark\":\" 暂停交易\",\n" +
                "\"investType\":3,\n" +
                "\"investTypeMark\":\" 混合型\",\n" +
                "\"investStyle\":1,\n" +
                "\"investStyleMark\":\" 成长型\"\n" +
                "}";


        String managerStr = "[" +
                "{ 'individualName':'Gates','fundIndividualInfo':{'name':'Gates','resume':'nandfsdfsdfsd'}}" +

                "]";

        String s1 = "[\n" +
                "  {\n" +
                "    \"condition\": \"1  天 ≤  持有期限 < 7  天\",\n" +
                "    \"rate\": \"1.50%\"\n" +
                "  },\n" +
                "  {\n" +
                "    \"condition\": \"7  天 ≤  持有期限 < 30  天\",\n" +
                "    \"rate\": \"0.75%\"\n" +
                "  },\n" +
                "  {\n" +
                "    \"condition\": \"30  天 ≤  持有期限 < 90  天\",\n" +
                "    \"rate\": \"0.50%\"\n" +
                "  },\n" +
                "  {\n" +
                "    \"condition\": \"90  天 ≤  持有期限 < 180  天\",\n" +
                "    \"rate\": \"0.50%\"\n" +
                "  },\n" +
                "  {\n" +
                "    \"condition\": \"180  天 ≤  持有期限 < 365  天\",\n" +
                "    \"rate\": \"0.10%\"\n" +
                "  },\n" +
                "  {\n" +
                "    \"condition\": \"1  年 ≤  持有期限 < 2  年\",\n" +
                "    \"rate\": \"0.05%\"\n" +
                "  },\n" +
                "  {\n" +
                "    \"condition\": \" 持有期限 ≥ 2  年\",\n" +
                "    \"rate\": \"0.00%\"\n" +
                "  }\n" +
                "]";


        JMFundExtInfo extInfo = new JMFundExtInfo();
        extInfo.setFundCode("test_2");
        extInfo.setFundInfo(str);
        extInfo.setFundManager(managerStr);
        extInfo.setRedeemFee(s1);

        ImportResponse importResponse = jmFundService.importExtInfo(extInfo);
        print(importResponse);

    }

    void test2() {
        JMFundBasicInfo basicInfo = new JMFundBasicInfo();
        basicInfo.setFundCode("000022");
        basicInfo.setName("南方中票A");
        basicInfo.setProductionStatus(ProductionStatus.Both);
        basicInfo.setRiskClass(RiskClass.Low);
        basicInfo.setRiskHint("基金的过往业绩不预示其未来表现，市场有风险，投资需谨慎");

        List<ProductionBizInfo> bizInfos = new ArrayList<ProductionBizInfo>();
        bizInfos.add(new ProductionBizInfo(BizType.Fundin, "T+1", "", ValidStatus.Valid));
        bizInfos.add(new ProductionBizInfo(BizType.Fundout, "T+3", "x", ValidStatus.Valid));
//        bizInfos.add(new ProductionBizInfo(BizType.Append, "T+3", "x", ValidStatus.Valid));
        basicInfo.setBizInfos(bizInfos);

        List<ProductionLimit> limits = new ArrayList<ProductionLimit>();
        ProductionLimit limit = new ProductionLimit();
        limit.setBizType(BizType.Fundin);
        limit.setMinAmount(new BigDecimal(10));
        limit.setUnitAmount(new BigDecimal(10));
        limits.add(limit);

        limit = new ProductionLimit();
        limit.setBizType(BizType.Fundout);
        limit.setMinAmount(new BigDecimal(10));
        limit.setLeastLeft(new BigDecimal(0));
        limits.add(limit);

        basicInfo.setLimits(limits);


        ImportResponse resp = jmFundService.importBasicInfo(basicInfo);
        print(resp);
    }
}
